package com.itfenghuang.day18_lx;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/*
编写一个应用程序，可以让用户在窗体网页上输入名称、密码，若名称为caterpillar且密码为123456，
则显示一个HTML页面响应并有“登录成功”字样，否则显示“登录失败”字样，并由一个超链接连回窗体网页。
注意：不可在地址栏上出现用户输入的名称、密码
 */

public class A01_作业 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String name="caterpillar";
        String mima ="123456";
        String m = req.getParameter("username");
        String pw = req.getParameter("password");
        PrintWriter pow = resp.getWriter();

        if ((m.equals(name))&&(pw.equals(mima))){
            pow.write("登陆成功");
        }else {
            resp.sendRedirect("static/hello.html");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
